package vue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JFormattedTextField;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.text.MaskFormatter;

import modele.Commande;
import modele.util.ModePaiement;

import java.awt.CardLayout;
import java.awt.Color;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class ParCarteBancaire extends JPanel {
	public class ValiderListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent arg0) {
			
			CardLayout c1= (CardLayout)getParent().getLayout();
			
			c1.show(getParent(), "name_recapt");

		}

	}

	private JTextField textFieldNomCarte;
	private JLabel lblInvalideChiffres;
	private Commande commande= new Commande();
	private JButton btnValider;

	
	/**
	 * Create the panel.
	 */
	public ParCarteBancaire() {
		setLayout(null);
		
		JLabel lblNom = new JLabel("Nom:");
		lblNom.setBounds(25, 31, 46, 14);
		add(lblNom);
		
		textFieldNomCarte = new JTextField();
		textFieldNomCarte.setBounds(62, 28, 86, 20);
		add(textFieldNomCarte);
		textFieldNomCarte.setColumns(10);
		
		JLabel lblNumroDeLa = new JLabel("Num\u00E9ro de la carte");
		lblNumroDeLa.setBounds(10, 69, 110, 14);
		add(lblNumroDeLa);
		
		JFormattedTextField formattedTextFieldNumberCarte = new JFormattedTextField(createFormatter("##############"));
		formattedTextFieldNumberCarte.setBounds(104, 66, 86, 20);
		add(formattedTextFieldNumberCarte);
		
		JLabel lblNewLabel = new JLabel("Cryptogramme visuel");
		lblNewLabel.setBounds(10, 133, 120, 14);
		add(lblNewLabel);
		
		JFormattedTextField formattedTextFieldCrypto = new JFormattedTextField(createFormatter("###"));
		formattedTextFieldCrypto.setBounds(140, 131, 74, 17);
		add(formattedTextFieldCrypto);
		
	    btnValider = new JButton("Valider");
		btnValider.setBounds(182, 192, 89, 23);
		btnValider.addActionListener(new ValiderListener());
		add(btnValider);
		
		JLabel lblDateDexpiration = new JLabel("Date d'expiration");
		lblDateDexpiration.setBounds(10, 108, 86, 14);
		add(lblDateDexpiration);
		
		JComboBox comboBox = new JComboBox();
		comboBox.setBounds(114, 102, 28, 20);
		add(comboBox);
		
		JLabel label = new JLabel("/");
		label.setBounds(144, 106, 4, 14);
		add(label);
		
		JComboBox comboBox_1 = new JComboBox();
		comboBox_1.setBounds(152, 102, 28, 20);
		add(comboBox_1);
		
		lblInvalideChiffres = new JLabel("Invalide (14 chiffres)");
		lblInvalideChiffres.setForeground(Color.RED);
		lblInvalideChiffres.setBounds(210, 69, 120, 14);
		lblInvalideChiffres.setVisible(false);
		add(lblInvalideChiffres);

	}
	
	protected MaskFormatter createFormatter(String s) {
	    MaskFormatter formatter = null;
	    try {
	        formatter = new MaskFormatter(s);
	    } catch (java.text.ParseException exc) {
	       lblInvalideChiffres.setVisible(true);
	        System.exit(-1);
	    }
	    return formatter;
	}

	public Commande getCommande() {
		return commande;
	}

	public void setCommande(Commande commande) {
		this.commande = commande;
	}
}
